Skip to content

feat(stellar): fetch policy observability - #642

Open
Julink-eth wants to merge 6 commits into
mainfrom
feat/stellar-fetch-policy-observability
Open

Julink-eth wants to merge 6 commits into
mainfrom
feat/stellar-fetch-policy-observability

Conversation

@Julink-eth

@Julink-eth Julink-eth commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Explanation

Wires the Stellar snap into the fetch policy observability added in #566, as Solana (#583) and Tron already do.

  • The Stellar RPC, Price API, Token API and Security Alerts API policies now get analytics and trackError, through a new utils/analytics.ts. Outages send "Snap Service Degraded" and "Snap Service Unavailable" to Segment, and calls that use up their retries are reported to Sentry once, sanitised.
  • trackError skips errors a policy already reported (isReportedFetchPolicyError), so callers don't report them again. Every Stellar wrapper keeps the policy error as cause, so the check works through them.
  • The Horizon policy only gets analytics, with no trackError.

Why Horizon has no trackError

The Horizon policy runs inside the Stellar SDK as its HTTP adapter. For reads (loadAccount, fetchBaseFee, transactions()), the SDK catches the policy error and rethrows a new NetworkError, NotFoundError or plain Error, without cause (CallBuilder._handleNetworkError). Callers can't recognise these as already reported, so giving the policy trackError would send every Horizon give-up to Sentry twice. Restoring the link would mean patching SDK internals.
So Horizon gets the Segment events, and its Sentry reporting stays as today: callers report the SDK's error. The known cost is that Horizon open-circuit errors keep reaching Sentry once per blocked call, as they do now.
Stellar RPC doesn't have this problem: the SDK passes its errors through unchanged.

createTrackError's default shouldTrack now also skips errors a fetch policy already reported, so Stellar, Solana and Tron drop their identical override (no behaviour change).

References

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

@Julink-eth
Julink-eth requested review from a team as code owners November 17, 2026 08:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues remain for the Stellar fetch-policy observability changes.

No open issues 🎉

What changed in this PR

This PR connects the Stellar snap to the shared fetch-policy observability introduced in #566, following Solana’s adoption in #583.

Changes:

  • Adds shared analytics and sanitized Sentry reporting for Stellar RPC, Price, Token, and Security Alerts policies; Horizon receives analytics only to avoid duplicate Sentry reports.
  • Prevents reporting errors already handled by fetch policies and user-rejected requests.
  • Adds reporting-wiring and error-filter tests, updates coverage thresholds, and documents the behavior.
File Description
packages/​stellar-wallet-snap/​vitest.config.ts Slightly raises coverage thresholds.
packages/​stellar-wallet-snap/​src/​utils/​errors.ts Filters already-reported policy errors and user rejections.
packages/​stellar-wallet-snap/​src/​utils/​errors.test.ts Tests error-reporting filters and ordinary error reporting.
packages/​stellar-wallet-snap/​src/​utils/​analytics.ts Centralizes analytics and fetch-policy reporting options.
packages/​stellar-wallet-snap/​src/​services/​price/​price-api/​PriceApiClient.ts Enables Price API policy reporting.
packages/​stellar-wallet-snap/​src/​services/​price/​price-api/​PriceApiClient.test.ts Verifies Price API reporting configuration.
packages/​stellar-wallet-snap/​src/​services/​network/​NetworkService.ts Enables Horizon analytics and RPC analytics/Sentry reporting.
packages/​stellar-wallet-snap/​src/​services/​network/​NetworkService.test.ts Verifies distinct Horizon and RPC reporting configurations.
packages/​stellar-wallet-snap/​src/​services/​asset-metadata/​token-api/​TokenApiClient.ts Enables Token API policy reporting.
packages/​stellar-wallet-snap/​src/​services/​asset-metadata/​token-api/​TokenApiClient.test.ts Verifies Token API reporting configuration.
packages/​stellar-wallet-snap/​src/​context.ts Reuses shared analytics and enables Security Alerts policy reporting.
packages/​stellar-wallet-snap/​snap.manifest.json Updates the bundle checksum.
packages/​stellar-wallet-snap/​CHANGELOG.md Documents observability behavior and Horizon’s reporting exception.

Review effort: Balanced

@Julink-eth

Copy link
Copy Markdown
Contributor Author

@metamaskbot publish-preview

@github-actions

Copy link
Copy Markdown
Contributor

Preview builds have been published. Learn how to use preview builds in other projects.

Expand for full list of packages and versions.
@metamask-previews/bitcoin-wallet-snap@3.3.0-preview-9a2c0cc8
@metamask-previews/snap-networks-utils@3.2.0-preview-9a2c0cc8
@metamask-previews/solana-wallet-snap@7.3.0-preview-9a2c0cc8
@metamask-previews/stellar-wallet-snap@2.1.0-preview-9a2c0cc8
@metamask-previews/tron-wallet-snap@4.4.1-preview-9a2c0cc8

this.#policy = createFetchPolicy({
service: 'price_api',
logger: _logger,
...fetchPolicyReporting,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

im wondering why we dont move those api client into the share utils first, as they should be the same

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They could, but the problem today is that they differ (Bitcoin is on /v1 with a different response; Solana and Tron add caching and chunking; Stellar doesn't). Moving them is a refactor across 4 snaps so we could do it but it's a PR own its own imo not related to this one.

getSnapProvider,
logError: logger.error.bind(logger),
shouldTrack: (error) =>
!(error instanceof UserRejectedRequestError) &&

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is a default shouldTrack from the utils ? no ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, a small change is needed in the utils package though (add isReportedFetchPolicyError to defaultShouldTrack) but it's small so I'll do it in this PR.

@sonarqubecloud

Copy link
Copy Markdown

This branch was previously deployed

1 inactive (outdated) deployment
default-branch — a2fdd3c1 Deployed Nov 17, 2026 by Julink-eth via Determine whether this PR is a release PR #2430
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants